<?php

namespace Modules\Admin\Models;
use Illuminate\Support\Facades\DB;
class Area extends BaseModel
{
	/**
	 * @name  删除
	 * @param id 当前删除数据id
	 * @return 返回删除结果
	 */
	public function area_delete($id,$url){
		$arr = $this->dels($id);
		$arr[] = (int)$id;
		return $this->common_destroy($arr,$url);
		 
	}
	/**
	 * @name  获取id
	 * @param id 当前删除数据id
	 * @return 返回获取当前的删除id的其他子id
	 */
	//
	private function dels($id){
		$cate = $this->get();
		return $this->delsort($cate,$id);
	}
	/**
	 * @name  递归遍历数据
	 * @param cate 全部数据
	 * @param id 当前删除数据id
	 * @return 返回获取当前的删除id的其他子id
	 */
	private function delsort($cate,$id){
		//创建新数组
		static $arr=array();
		foreach($cate as $v){
			if($v->pid == $id){
				$arr[] = $v->id;
				$this->delsort($cate,$v->id);
			}
		}
		return $arr;
	}
	
	
	/**
	 * @name  获取全称路径
	 * @param data 当前数据
	 * @return 返回删除结果
	 */
	public function merger_name($data){
		if(isset($data['pid'])){
			$str = $this->names($data['pid']);
			$data['merger_name'] = $str . $data['name'];
		}else{
			$data['pid'] = 0; 
			$data['merger_name'] = $data['name'];
		}
		return $data;
	}
	
	/**
	 * @name  递归遍历获取名称
	 * @param id 上级id
	 * @return 返回组合完成数据
	 */
	private function names($id){
		//创建新数组
		static $str= '';
		$res = $this->find($id);
		$str = $res->name . ',' . $str;
		if($res->pid == 0){
			return $str;
		}else{
			$this->names($res->pid);
		}
	}
}
